package main

import "fmt"

// 利用通道(channel)存储fibonacci数列
func fibonacci(cap int, ch chan int) {
	x, y := 0, 1
	for i := 0; i < cap; i++ {
		ch <- x
		x, y = y, x+y
	}
	close(ch)
}

func main() {
	ch := make(chan int, 7)

	go fibonacci(cap(ch), ch)
	for i := range ch {
		fmt.Printf("%d ", i)
	}
	fmt.Println()
}
